using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Wzh_CheckAB
{
    public class CheckABEx : MonoBehaviour
    {
        private string assetBundlePath;
        private string assetBundlePathback;
        public static CheckABEx I;
        public ABInfoUI infoUI;
        public Button UseABBtn;
        public Button BackABBtn;
        public Button ExitBtn;
        private void Start()
        {
            I = this;
            InitAssetBundlePath();
            UseABBtn.onClick.AddListener(OnUseABBtn);
            BackABBtn.onClick.AddListener(OnBackABBtn);
            ExitBtn.onClick.AddListener(OnExitBtn);
            OnExitBtn();
        }
        private void InitAssetBundlePath()
        {
            assetBundlePath = Application.dataPath + "/../abdata";
            assetBundlePathback = Application.dataPath + "/../abdata_Back";

            string abdataPath = Application.dataPath + "/../abdataPath.json";
            string pathStr = PHHelper.GetFileAllInfo(abdataPath);
            if (string.IsNullOrEmpty(pathStr)) return;
            pathStr = pathStr.Replace(@"\", @"\\");
            var abdataPathInfo = JsonUtility.FromJson<AbdataPathInfo>(pathStr);
            if (abdataPathInfo == null) return;
            if (string.IsNullOrEmpty(abdataPathInfo.abdata) == false)
                assetBundlePath = abdataPathInfo.abdata;
            if (string.IsNullOrEmpty(abdataPathInfo.abdata_Back) == false)
                assetBundlePathback = abdataPathInfo.abdata_Back;
        }
        private void OnUseABBtn()
        {
            ShowABInfo(true);
            infoUI.ShowUI(new ABDataManager(assetBundlePath, assetBundlePathback), OnExitBtn);
        }
        private void OnBackABBtn()
        {
            ShowABInfo(true);
            infoUI.ShowUI(new ABDataManager(assetBundlePathback, assetBundlePath), OnExitBtn);
        }
        private void OnExitBtn()
        {
            ShowABInfo(false);
        }

        private void ShowABInfo(bool isActive)
        {
            UseABBtn.gameObject.SetActive(!isActive);
            BackABBtn.gameObject.SetActive(!isActive);
            ExitBtn.gameObject.SetActive(isActive);
            infoUI.gameObject.SetActive(isActive);
        }

        public class AbdataPathInfo
        {
            public string abdata;
            public string abdata_Back;
        }

    }

}

